# encoding: UTF-8
"""

@author = 李林名
@email = lishuai1199@qq.com
@create_time = 2022/11/24 19:30

"""

from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

# #1.使用xpath选择器,使用绝对路径获取元素,并显示其innerHTML
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##xpath选择器获取元素
# element=wd.find_element(By.XPATH,'/html/body/div/p')
# print(element.get_attribute('innerHTML'))
# sleep(2)


# #2.使用xpath选择器,使用相对路径获取元素,并显示:       北京 上海
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##xpath选择器获取元素
# elements=wd.find_elements(By.XPATH,'//div/div/div/p')
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)


# #3.使用xpath选择器,使用通配符获取元素,并显示:
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##xpath选择器获取元素
# elements=wd.find_elements(By.XPATH,'//div/div/div//*')
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)


# #4.使用xpath选择器,使用id获取元素,并显示:     纽约,休斯顿
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##根据id获取元素
# elements=wd.find_elements(By.XPATH,"//*[@id='west']/p")
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)


# #5.使用xpath选择器,使用class获取元素,并显示:      北京
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##根据id获取元素
# elements=wd.find_elements(By.XPATH,"//*[@class='capital huge-city']")
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)


# #6.使用xpath选择器,使用属性的值部分分布情况,获取元素,并显示:    纽约
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##根据id获取元素
# elements=wd.find_elements(By.XPATH,"//*[starts-with(@id,'new')]")
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)


# #7.使用xpath选择器,使用p[2]类序分布情况,获取元素,并显示:    上海,休斯顿
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##根据id获取元素
# elements=wd.find_elements(By.XPATH,"//div/div//p[2]")
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)


# #7.使用xpath选择器,使用p[last()]获取元素,并显示:    芝加哥
# wd = webdriver.Chrome()
# wd.get('https://cdn2.byhy.net/files/selenium/test1.html')
#
# ##根据id获取元素
# elements=wd.find_elements(By.XPATH,"//div/div/div[last()]/span[last()]/p")
# for element in elements:
#     print(element.get_attribute('innerHTML'))
# sleep(2)


#8.使用xpath选择器,使用[position()>=last()]获取元素,并显示:    芝加哥
wd = webdriver.Chrome()
wd.get('https://cdn2.byhy.net/files/selenium/test1.html')

##根据id获取元素
elements=wd.find_elements(By.XPATH,"//span[position()>=last()]/p[position()>=last()]")
for element in elements:
    print(element.get_attribute('innerHTML'))
sleep(2)
